package com.wyl.controller;

import com.wyl.condition.query.Condition;
import com.wyl.dto.basic.PortalRunParam;
import com.wyl.showtype.ShowType;
import com.wyl.showtype.basic.table.TableVo;
import com.wyl.showtype.basic.table.vo.TableHeaderVo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 吴宇亮 on 2023/4/21 13:27
 */
@RestController
public class ConditionController {

    /**
     * {
     *     "type": "group",
     *     "operator": "and",
     *     "conditions": [
     *         {
     *             "type": "value",
     *             "key": "name",
     *             "operator": "equal",
     *             "value": [
     *                 "张三"
     *             ]
     *         },
     *         {
     *             "type": "group",
     *             "operator": "or",
     *             "conditions": [
     *                 {
     *                     "type": "value",
     *                     "key": "country",
     *                     "operator": "equal",
     *                     "value": [
     *                         "中国"
     *                     ]
     *                 },
     *                 {
     *                     "type": "value",
     *                     "key": "country",
     *                     "operator": "equal",
     *                     "value": [
     *                         "美国"
     *                     ]
     *                 }
     *             ]
     *         }
     *     ]
     * }
     * @param condition
     */
    @RequestMapping("/resolveParam")
    public void resolveParam(@RequestBody Condition condition) {
        System.out.println("resolveParam: " + condition.getClass());
    }


    @RequestMapping("/run")
    public ShowType run(@RequestBody PortalRunParam portalRunParam) {
        System.out.println("run: " + portalRunParam.getClass());
        TableVo tableVo = new TableVo()
                .setHeaders(List.of(
                        new TableHeaderVo().setName("姓名"),
                        new TableHeaderVo().setName("年龄")
                ))
                .setContents(List.of(
                        List.of("张三", "20"),
                        List.of("李四", "21")
                ));
        return tableVo;
    }

}
